package cn.mumzone.basic.loading.dialog;

import android.graphics.Color;
import android.graphics.ColorSpace;
import android.support.v7.widget.AppCompatImageView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.mumzone.basic.R;
import cn.mumzone.basic.util.DisplayUtil;


/**
 * 作者：joseph_l on 11/12/15 14:53
 * 邮箱：ljt@yonyou.com
 */
public class VaryViewHelperController {
    private IVaryViewHelper helper;

    public VaryViewHelperController(View view) {
        this(new VaryViewHelper(view));
    }

    public VaryViewHelperController(IVaryViewHelper helper) {
        super();
        this.helper = helper;
    }

    /**
     * 可点击的无数据
     */
    public void showEmpty(int emptyImg, String emptyMsg, String emptyGoText, View.OnClickListener onClickListener) {
        View layout = helper.inflate(R.layout.message_center);
        TextView textView = layout.findViewById(R.id.message_info);
        if (!TextUtils.isEmpty(emptyMsg)) {
            textView.setText(emptyMsg);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
            layoutParams.topMargin = DisplayUtil.dip2px(textView.getContext(), 10f);
            textView.setLayoutParams(layoutParams);
        } else {
            textView.setText("抱歉,暂未获取到数据!");
        }

        ImageView imageView = layout.findViewById(R.id.message_icon);
        if (emptyImg != -1) {
            imageView.setVisibility(View.VISIBLE);
            imageView.setImageResource(emptyImg);
        } else {
            imageView.setVisibility(View.GONE);
        }

        TextView tvEmptyGo = layout.findViewById(R.id.tv_empty_go);
        if (!TextUtils.isEmpty(emptyGoText)) {
            tvEmptyGo.setText(emptyGoText);
            if (null != onClickListener) {
                tvEmptyGo.setVisibility(View.VISIBLE);
                tvEmptyGo.setOnClickListener(onClickListener);
            }
        } else {
            tvEmptyGo.setVisibility(View.GONE);
        }

        helper.showLayout(layout);
    }

    public void showEmpty(int emptyImg, String emptyMsg, String secondMsg) {
        View layout = helper.inflate(R.layout.message_center);
        TextView textView = layout.findViewById(R.id.message_info);
        if (!TextUtils.isEmpty(emptyMsg)) {
            textView.setText(emptyMsg);
            textView.setTextColor(Color.parseColor("#333333"));
        } else {
            textView.setText("抱歉,暂未获取到数据!");
        }

        ImageView imageView = layout.findViewById(R.id.message_icon);
        if (emptyImg != -1) {
            imageView.setVisibility(View.VISIBLE);
            imageView.setImageResource(emptyImg);
        } else {
            imageView.setVisibility(View.GONE);
        }

        TextView tvEmptyGo = layout.findViewById(R.id.tv_empty_go);
        if (!TextUtils.isEmpty(secondMsg)) {
            tvEmptyGo.setText(secondMsg);
            tvEmptyGo.setTextColor(Color.parseColor("#999999"));
            tvEmptyGo.setBackground(null);
        } else {
            tvEmptyGo.setVisibility(View.GONE);
        }

        helper.showLayout(layout);
    }

    /**
     * 网络错误
     */
    public void showNetError(boolean clickable, View.OnClickListener onClickListener) {
        View layout = helper.inflate(R.layout.pos_net_error);
        TextView tvRefresh = layout.findViewById(R.id.tv_refresh);
        if (clickable) {
            tvRefresh.setVisibility(View.VISIBLE);
            tvRefresh.setOnClickListener(onClickListener);
        } else {
            tvRefresh.setVisibility(View.GONE);
        }
        helper.showLayout(layout);
    }

    /**
     * 不可点击的无数据
     *
     * @param emptyImg
     * @param emptyMsg
     */
    public void showEmpty(int emptyImg, String emptyMsg) {
        this.showEmpty(emptyImg, emptyMsg, null, null);
    }

    public void restore() {
        helper.restoreView();
    }

}
